Add dialect setting with optional fallback dialects#49
Open
sammcj wants to merge 1 commit into
Open
Conversation
Harper can lint against different English dialects, but the extension always used the default (American), so non-American spellings like "colour" and "organisation" were flagged as misspellings with no way to change it. Add a `dialect` setting accepting "American" (default), "British", "Australian", "Canadian", or "Indian". It is passed to Harper via `setDialect`, so it controls both which spellings are flagged and which spellings suggestions prefer. Add a `dialectFallbacks` setting listing additional dialects whose spellings are also accepted. A Spelling lint from the primary dialect is kept only if every fallback dialect also flags the same span; if any fallback accepts the word it is not flagged. This lets you, for example, prefer Australian suggestions while still accepting American spellings. Suggestions always come from the primary dialect. Implementation: - Dialect names are parsed and validated in settings.ts as plain strings, keeping that module free of the harper.js (WebAssembly) import so it stays fast to unit test. Invalid names, duplicates, and the primary dialect are dropped from the fallback list. - lint.ts maps the names to Harper's Dialect enum, sets the dialect on the linter, and creates one extra LocalLinter per fallback dialect used only to test whether a word is an accepted spelling there. - Fallback filtering runs one extra lint pass per fallback dialect and is skipped entirely when none are configured. The keep/drop decision lives in a small pure helper (fallback.ts) so it can be unit tested without loading WebAssembly. Defaults preserve the previous behaviour (American, no fallbacks). README documents both settings; new unit tests cover settings parsing and the fallback decision.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds two settings to
extension.markeditProofreadingthat let you choose which English dialect Harper checks against, and optionally accept spellings from additional dialects.Harper supports several English dialects, but the extension always used the default (American), so non-American spellings like "colour" and "organisation" were flagged as misspellings with no way to change it.
Closes #48
What changed
dialect: the English dialect Harper checks against. One of"American"(default),"British","Australian","Canadian", or"Indian". It is passed to Harper viasetDialect, so it controls both which spellingsare flagged and which spellings suggestions prefer.
dialectFallbacks: additional dialects whose spellings are also accepted (default[]). A Spelling lint from the primary dialect is kept only if every fallback dialect also flags the same word; if any fallback accepts the word, it is not flagged. Suggestions always come from the primarydialect.Example
{ "extension.markeditProofreading": { "dialect": "Australian", "dialectFallbacks": ["American"] } }With this config, Australian spellings are suggested for genuine misspellings, while American spellings such as "color" and "organization" are accepted rather than flagged. With dialectFallbacks omitted, those American spellings would be flagged.
Implementation notes
Behaviour and compatibility
Defaults preserve the previous behaviour: dialect defaults to "American" and dialectFallbacks to [], so existing installs lint exactly as before unless these settings are set.
Testing
Notes
Per the contribution guidelines, happy to scope this down if preferred: the dialect setting is a thin pass-through to Harper's native setDialect and stands on its own, while dialectFallbacks is the more opinionated part (it adds one lint pass per fallback). The two are cleanly separable if you would rather land dialect first.